<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>#{bundel.loan}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
            <h:form prependId="false" >
               <script type="text/javascript">  
                   var doInitForm=false;
                   var tofocus;
                   
                   function changeFocus(nextfcs) {tofocus=nextfcs;}
                   function setDoInitForm(st) {doInitForm=st;}
                   function focusState(xhr, status, args) {  
                       if(args.validationFailed || !args.success) {}
                       else document.getElementById(tofocus).focus();
                       return false;
                   }
                                      
                   function handleCompleteSaving(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {
                        }else setTimeout(function() {if (doInitForm==true) btnNewLoansim.jq.click();}, 3000);
                    }
                    
                </script>  
                
                <p:outputPanel autoUpdate="true">
                <p:toolbar>
                    <p:toolbarGroup align="left">
                        <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document"
                                         action="#{loansimulateBean.newData()}" process="@this" update="displayLoansim" 
                                         widgetVar="btnNewLoansim" oncomplete="setDoInitForm(false);"
                                         rendered="#{menuBean.cekButtonAccess(308,'INS;')}" >
                            <pe:resetEditableValues for="displayLoansim"/>  
                        </p:commandButton>
                        
                        <p:commandButton value="#{bundle.btnSimulate}" icon="ui-icon-search"
                                         rendered="#{menuBean.cekButtonAccess(308,'INS;')}"
                                          action="#{loansimulateBean.simulasi()}" process="@form" update="dtLoansim" >
                        </p:commandButton>
                        
                        <p:commandButton type="push" action="#{rptLoansimBean.execute(loansimulateBean.loansimulates)}" value="#{bundle.btnPrint}"  
                                         ajax="false" image="ui-icon-print" rendered="#{menuBean.cekButtonAccess(308,'PRN;')}" >
                            <f:setPropertyActionListener value="#{loansimulateBean.loansimulates}" target="#{rptLoansimBean.sim}" />
                            <f:setPropertyActionListener value="#{loansimulateBean.loan.period}" target="#{rptLoansimBean.period}" />
                            <f:setPropertyActionListener value="#{loansimulateBean.loan.loanprod.productName}" target="#{rptLoansimBean.productName}" />
                            <f:setPropertyActionListener value="#{constantaBean.getInterestTypeText(loansimulateBean.loan.interestType)}" target="#{rptLoansimBean.metod}" />
                            <f:setPropertyActionListener value="#{loansimulateBean.loan.interestRate}" target="#{rptLoansimBean.interestRate}" />
                            <f:setPropertyActionListener value="#{loansimulateBean.loan.principalAmount}" target="#{rptLoansimBean.principalAmount}" />
                        </p:commandButton>
                    </p:toolbarGroup>
                    
                    <p:toolbarGroup align="right">
                        <p:commandButton id="doNothingLoansim" type="button" value="" style="width: 0px; height: 0px;"/> 
                         <p:defaultCommand target="doNothingLoansim"/> 
                    </p:toolbarGroup>
                </p:toolbar>
                </p:outputPanel>  
                             
                
                <h:panelGrid id="displayLoansim" styleClass="addELIT" cellpadding="0" border="0" >
                    <h:panelGrid columns="2" columnClasses="panelGridId,panelGridId" cellpadding="0" cellspacing="5">
                        <p:panel header="#{bundle.loanLedgend}">
                            <h:panelGrid columns="3" cellpadding="0" cellspacing="5">
                                <h:outputLabel value= "#{bundle.loanprod}" /><h:outputLabel value= " : " />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" >
                                    <p:selectOneMenu value="#{loansimulateBean.loan.loanprod.loanprodId}" id="loansimLoanProdId" label="#{bundle.loanprod}" 
                                            requiredMessage="#{bundle.loanprod} #{bundle.requiredInput}" 
                                            required="true" style="width: 151px;" disabled="#{!loansimulateBean.editMode}">
                                        <f:selectItem itemLabel="" itemValue="" />
                                        <f:selectItems value="#{loansimulateBean.avaibleProduct}" />
                                        <p:ajax update="msgloansimLoanProdId loansimInterestRate" listener="#{loansimulateBean.handleProdChange}" />  
                                    </p:selectOneMenu>
                                    <p:message id="msgloansimLoanProdId" for="loansimLoanProdId" display="icon" />
                                </h:panelGrid>
                                
                                <h:outputLabel value= "#{bundle.loanDate}" /><h:outputLabel value= " : " />
                                <h:outputText value="#{loansimulateBean.loan.loanDate}" />

                                <h:outputLabel value= "#{bundle.loanAmount}" /><h:outputLabel value= " : " />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                    <pe:inputNumber decimalSeparator="." thousandSeparator="," maxValue="99999999999999999999.99" minValue="0" 
                                        styleClass="money" value="#{loansimulateBean.loan.principalAmount}" style="width: 150px;"
                                        requiredMessage="#{bundle.loanAmount} #{bundle.requiredInput}"
                                        required="true" id="loansimPrincipalAmount" disabled="#{!loansimulateBean.editMode}">
                                        <p:ajax update="msgloansimPrincipalAmount loansimInterestRate" listener="#{loansimulateBean.getInterestRate}" process="@this" partialSubmit="false"/>
                                    </pe:inputNumber>
                                    <p:message id="msgloansimPrincipalAmount" for="loansimPrincipalAmount" display="icon" />
                                </h:panelGrid>    
                                
                                <h:outputLabel style="padding:0 15px 0 0;" value= "#{bundle.interestRate}" /><h:outputLabel value= " : " />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                    <pe:inputNumber decimalSeparator="." thousandSeparator="," maxValue="999.99" minValue="0" symbol=" %" symbolPosition="s"
                                        styleClass="percent" value="#{loansimulateBean.loan.interestRate}" style="width: 150px;" disabled="#{!loansimulateBean.editMode}"
                                        required="true" requiredMessage="#{bundle.interestRate} #{bundle.requiredInput}" id="loansimInterestRate" >
                                        <p:ajax update="msgloansimInterestRate" process="@this"/>
                                    </pe:inputNumber>
                                    <p:message id="msgloansimInterestRate" for="loansimInterestRate" display="icon" />
                                </h:panelGrid>    
                                
                                <h:outputLabel value= "#{bundle.interestType}" /><h:outputLabel value= " : " />
                                <p:selectOneMenu value="#{loansimulateBean.loan.interestType}" style="width: 151px" disabled="#{!loansimulateBean.editMode}">
                                    <f:selectItem itemValue="F" itemLabel="#{bundle.interestTypeFlat}"/>
                                    <f:selectItem itemValue="E" itemLabel="#{bundle.interestTypeEffective}"/>
                                </p:selectOneMenu>

                                <h:outputLabel value= "#{bundle.disbursementDate}" /><h:outputLabel value= " : " />
                                <p:calendar value="#{loansimulateBean.loan.disbursementDate}" pattern="dd/MM/yyyy" 
                                            size="8" navigator="true" showOn="button" disabled="#{!loansimulateBean.editMode}">
                                    <p:ajax event="dateSelect" update="loansimDuedate" listener="#{loansimulateBean.handleDisbDateSelect}" />  
                                </p:calendar>
                                
                                <h:outputLabel value= "#{bundle.period}" /><h:outputLabel value= " : " />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                    <pe:inputNumber decimalSeparator="." thousandSeparator="," maxValue="1000" minValue="0" 
                                                    symbol=" Bulan" symbolPosition="s" 
                                                    value="#{loansimulateBean.loan.period}" style="width: 95px; text-align: right;"
                                                disabled="#{!loansimulateBean.editMode}">
                                        <p:ajax update="loansimDuedate" listener="#{loansimulateBean.handlePeriod}" partialSubmit="false" />
                                    </pe:inputNumber>
                                </h:panelGrid>    
                                
                                <h:outputLabel value= "#{bundle.dueDate}" /><h:outputLabel value= " : " />
                                <p:calendar value="#{loansimulateBean.loan.dueDate}" pattern="dd/MM/yyyy" size="8"  id="loansimDuedate"
                                            navigator="true" showOn="button" disabled="#{!loansimulateBean.editMode}">
                                    <p:ajax event="dateSelect" listener="#{loansimulateBean.handleDueDateSelect}" />  
                                </p:calendar>
                            </h:panelGrid>
                        </p:panel>          
                        
                        <p:panel header="SIMULASI ANGSURAN">
                            <p:dataTable resizableColumns="true"  id="dtLoansim" value="#{loansimulateBean.loansimulates}" var="simulasi" rowIndexVar="noUrut">
                            
                                <p:column style="width: 12px;">
                                    <f:facet name="header">No</f:facet>
                                    <h:outputText value="#{noUrut+1}" />
                                </p:column>

                                <p:column style="width: 50px;">
                                    <f:facet name="header">#{bundle.date}</f:facet>
                                    <h:outputText value="#{simulasi.date}" />
                                </p:column>

                                <p:column style="width: 85px;">
                                    <f:facet name="header">Angsuran Pokok</f:facet>
                                    <h:outputText value="#{simulasi.amount}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>

                                <p:column style="width: 75px;">
                                    <f:facet name="header">Bunga</f:facet>
                                    <h:outputText value="#{simulasi.interest}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>

                                <p:column style="width: 90px;">
                                    <f:facet name="header">Total</f:facet>
                                    <h:outputText value="#{simulasi.total}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>
                                   <p:column style="width: 90px;">
                                       <f:facet name="header">Os Pokok  </f:facet>
                                       <h:outputText value="#{simulasi.outstanding}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>   
                                 <p:column style="width: 90px;">
                                     <f:facet name="header">Os Bunga</f:facet>
                                       <h:outputText value="#{simulasi.outstandingInterest}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>  
                                <p:column style="width: 100px;">
                                    <f:facet name="header">Keterangan</f:facet>
                                    <h:outputText value="#{simulasi.description}"  />
                                </p:column>
                                <p:columnGroup type="footer">  
                                    <p:row>  
                                        <p:column colspan="2" style="text-align:right" footerText="Totals:"/> 
                                        <p:column style="text-align:right" footerText="#{loansimulateBean.pricipalAmounts}" />    
                                        <p:column style="text-align:right" footerText="#{loansimulateBean.interestAmounts}" />    
                                        <p:column style="text-align:right" footerText="#{loansimulateBean.amounts}" />    
                                        <p:column style="text-align:right" footerText="" />    
                                        <p:column style="text-align:right" footerText="" />    
                                        <p:column style="text-align:right" footerText="" />    
                                    </p:row>
                                </p:columnGroup>
                            </p:dataTable>
                        </p:panel>
                    </h:panelGrid> 
                </h:panelGrid>
            </h:form>
        </ui:composition>
    </h:body>
</html>